class Solution(object):
    def sortedSquares(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        n = len(nums)
        index = 1
        while index < n:
            if abs(nums[index]) > abs(nums[index - 1]):
                break
            else:
                index += 1
        index -= 1
        out = []
        out.append(abs(nums[index]) ** 2)
        left_index = index - 1
        right_index = index + 1
        while left_index >= 0 and right_index < n:
            if abs(nums[left_index]) > abs(nums[right_index]):
                out.append(abs(nums[right_index]) ** 2)
                right_index += 1
            else:
                out.append(abs(nums[left_index]) ** 2)
                left_index -= 1
        while left_index >= 0:
            out.append(abs(nums[left_index]) ** 2)
            left_index -= 1
        while right_index < n:
            out.append(abs(nums[right_index]) ** 2)
            right_index += 1
        return out





data = Solution()
nums = [-4, -1, 0, 3, 10]
print(data.sortedSquares(nums))
